package psu.kit;

public class ArrayHandler {

    public int handelArray(int[] array) {

        int count = countNumberInArray(array);
        if (count != 0 && count != array.length) {
            swapZero(array);
        }

        return count;
    }

    int countNumberInArray(int[] a) {
        int count = 0;
        for (int i = 0; i < a.length; ++i) {
            if (a[i] != 0) {
                ++count;
            }
        }
        return count;
    }

    void swapZero(int[] a) {
        int j = 0, k = 1;
        for (int i = 0; i < a.length - k; i++) {
            if (a[i] == 0) {
                while (a[a.length - k] == 0) {
                    k++;
                }
                a[i] = a[a.length - k];
                a[a.length - k] = j;
                k++;
            }
        }
    }
}
